package com.haifeng.asms.commons.utils;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * </p>
 *
 * @author: Haifeng
 * @date: 2020-06-20
 */
@Slf4j
@Component
@AllArgsConstructor
public class MessageUtil {

    private final MessageSource messageSource;

    /**
     * 获取单个国际化翻译值
     */
    public String get(Integer code) {
        try {
            return messageSource.getMessage(code.toString(), null, LocaleContextHolder.getLocale());
        } catch (Exception e) {
            return "";
        }
    }
}
